
Page({
  data: {
    bannerList: [], // 轮播图
    swiperCurrent: 0, // swiper索引
    navList: [{
      imgUrl: '/images/index/icon_reservation@2x.png',
      text: '预约看房',
      pageUrl: '/page/reservation/reservation',
      type: 1
    }, {
      imgUrl: '/images/index/icon_calculator@2x.png',
      text: '房贷计算器',
      pageUrl: '/page/mortgage/mortgage',
      type: 1
    }, {
      imgUrl: '/images/index/icon_property@2x.png',
      text: '热销楼盘',
      pageUrl: '/page/hot-property/hot-property',
      type: 1
    }, {
      imgUrl: '/images/index/icon_group@2x.png',
      text: '集团动态',
      pageUrl: '/page/dynamic/index',
      type: 1
    }],
    propertyList: [], //热销楼盘
    pageMsg: {
      pageNum: 1,
      isLastPage: false
    }, // 翻页信息
  },
  onLoad: function (t) {
    if (wx.canIUse('hideHomeButton') && wx.hideHomeButton) { wx.hideHomeButton() } 
    this.getBanner();
    this.getPropertyList({
      "hotSell": 1,
      "pageNum": 1,
      "pageSize": 10,
      "queryStatus": 0
    }, 'new');
    wx.showShareMenu({
      menus: ['shareAppMessage', 'shareTimeline']
    })
  },
  onShow(){
    
  },
  onShareAppMessage() {

  },
  onReachBottom() {
    if (!this.data.pageMsg.isLastPage) {
      this.getPropertyList({
        "hotSell": 1,
        "pageNum": this.data.pageMsg.pageNum + 1,
        "pageSize": 10,
        "queryStatus": 0
      }, 'next');
    }
  },
  swiperChange(event) {  // swiper切换事件
    let that = this;
    if (that.data.swiperCurrent !== event.detail.current) {
      that.setData({
        swiperCurrent: event.detail.current
      })
    }
  },
  toPage(e) { // 页面跳转
    let target = e.currentTarget.dataset;
    if (target.url) {
      switch (Number(target.type || 0)) {
        case 2:
          wx.switchTab({ url: target.url });
          break;
        default:
          wx.navigateTo({ url: target.url });
          break;
      }
    } else {
      console.warn('Not Page Url')
    }
  },

  // ------------------
  getBanner() { // 获取轮播图
    getApp().api.getBannerList().then(res => {
      this.setData({
        bannerList: res.data ? res.data : []
      })
    })
  },
  getPropertyList(params, type) { // 获取热销楼盘
    getApp().api.getHouseList(params).then(res => {
      this.setData({
        propertyList: type === 'new' ? res.data.list || [] : [...this.data.propertyList, ...(res.data.list || [])],
        pageMsg: {
          pageNum: res.data.pageNum,
          isLastPage: res.data.isLastPage
        }
      })
    })
  }
})
